<?php
class Application_Model_DbTable_Order extends Application_Model_DbTable_DomainObject{
	
	protected $_name = 'uuch_order';
	
	public function getMapper(){
		return array('id','userId','productTotal','parentId','orderNo',
				'status','dateCreated','dateConfrim','dateInStore',
				'shipFee','comment','sum','shopId','procureNo','logistics','logisticsNo','dateProcure','problemContent','ckPass');
	}
    
    public function getByUser($userId,$startTime,$endTime,$start,$pageSize){
        $db = $this->getAdapter();
        $filter = $db->quoteInto(' userId = ?', $userId);
        $filter .= $db->quoteInto(' and dateCreated >=?', $startTime);
        $filter .= $db->quoteInto(' and dateCreated <=?', $endTime);
        
        $rows = $this->fetchAll($filter);
        $result = array();
    	
    	foreach ($rows as $row)
    		array_push($result,$this->convertRowToObject($row));
    	return $result;

    }
    
    public function getUncomplate($userId){
    	$db = $this->getAdapter();
    	$sql='select count(*) from uuch_order where userid = '.$userId.' and status <'.Application_Model_Order::STATUS_COMPLATED;
    	
    	$result = $db->query($sql);
    	return $result->fetchColumn();
    }
}